package dao.impl;

import java.sql.*;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;

public class SQLConnection {
    	//Configuration de la connection
        private static final String SERVERNAME="127.0.0.1";
        private static final int PORTNUMBER = 1433;
        private static final String DB ="ELEC";            
	private static final String USER = "sa";
	private static final String PASSWORD = "systemforce";
	private Connection connection = null;
	
        //Connecter
	private void connecter() {
		try {
                        SQLServerDataSource DataSource =new SQLServerDataSource();
                        DataSource.setServerName(SERVERNAME);
                        DataSource.setPortNumber(PORTNUMBER);
                        DataSource.setDatabaseName(DB);
                        DataSource.setUser(USER);
                        DataSource.setPassword(PASSWORD);
    			connection=DataSource.getConnection();  
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}     
        
	//Deconnecter
        public void deconnecter() {
		try {
                    // fermer connection
                    if (connection != null) connection.close(); 
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
        
        //Getter
        public Connection getConnection () {
                connecter();
                return connection;
        }
}